import request from '@/utils/request'


export function getFile(data) {

  // let requestData = '';

  // for (let x in data) {
  //   requestData += `${x}=${data[x]}&`;
  // }
  return request({
    url: '/fileMgt/fileList',
    method: 'get',
    // data: requestData
    params:data
  })
}

export  function downLoadService(filename, token) {

  fetch(`/api/fileMgt/downLoad?url=${filename}`, {
    headers: {
      token
    }
  }).then(res => res.blob().then(blob => {
    let a = document.createElement('a');
    let url = window.URL.createObjectURL(blob);
    console.log(url);
    a.href = url;
    a.download = filename;
    a.click();
    window.URL.revokeObjectURL(url);
  }))
  // const res = await request({
  //   url: '/fileMgt/downLoad?url=' + url,
  //   method: 'post',
  //   responseType: 'blob'
  //   // data: requestData
  // })
  // console.log('res', res);
}

// export function getUpon(data) {

//   let requestData = '';

//   for (let x in data) {
//     requestData += `${x}=${data[x]}&`;
//   }
//   return request({
//     url: '/fileMgt/upload',
//     method: 'post',
//     data: requestData
//   })
// }

export function getDelete(data){
  // let requestData = '';

  // for (let x in data) {
  //   requestData += `${x}=${data[x]}&`;
  // }
   return request({
    url:'/fileMgt/deleteFile',
    method:'DELETE',
    // data:requestData
    params:data
   })
}